package com.znjc.iot.util;

import com.znjc.iot.domain.IotSerial;
import com.znjc.iot.serial.SerialPortHandler;
import com.znjc.iot.serial.SerialPortUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CommonUtil {
    //串口信息
    public static Map<String,SerialPortUtil> protUtils = new HashMap<>();
    /**
     * 已打开的串口集合
     */
    public static List<String> openComs = new ArrayList<String>();

    public static String deptName = "";

    public static Long commandId = 0L;
    public static Boolean setFlag = false;

    public static SerialPortUtil getSerialPortUtils(IotSerial serial) {
        SerialPortUtil serialPortUtil;
        //判断串口是否打开
        if (!CommonUtil.openComs.contains(serial.getSerialCode())) {
            //打开串口
            serialPortUtil = SerialPortHandler.openSerialPort(serial);
        } else {
            serialPortUtil = CommonUtil.protUtils.get(serial.getSerialCode());
        }
        return serialPortUtil;

    }
}
